<?php
/**
 * Created by PhpStorm.
 * User: lhl
 * Date: 2020/10/19
 * Time: 13:14
 * Features: 权限验证器
 */

namespace app\adminapiv3\validate;


use think\Validate;

class ServerPermissionValidate extends Validate
{
    //验证规则
    protected $rule = [
        'pid' => 'require|integer|egt:1',
        'name'  => 'require|chsAlpha|max:21',
        'is_menu' => 'require|in:0,1',
        'icon' => 'max:32',
        'route' => 'require|max:255',
        'redirect_url' => 'max:255',
        'menu_name' => 'max:85',
        'sorts' => 'integer|egt:0',
        'id' => 'require|integer|egt:1'
    ];


    //验证场景
    protected $scene = [
        //添加
        'add' => ['pid','name','is_menu','icon','route','redirect_url','menu_name','sorts'],
        //修改
        'modify' => ['id','pid','name','is_menu','icon','route','redirect_url','menu_name','sorts'],
        //详情
        'info' => ['id'],
        //删除
        'del' => ['id'],
    ];

    /**
     * 场景单独验证: 添加菜单
    */
    public function sceneAddMenu()
    {
        //如果是菜单,则redirect_url menu_name为必填
        return $this->only(['pid','name','is_menu','icon','route','redirect_url','menu_name','sorts'])
            ->append('redirect_url','require')
            ->append('menu_name','require')
            ->remove('route','require');
    }

    /**
     * 场景单独验证: 修改菜单
     */
    public function sceneModifyMenu(){
        //如果是菜单,则redirect_url menu_name为必填
        return $this->only(['pid','name','is_menu','icon','route','redirect_url','menu_name','sorts'])
            ->append('redirect_url','require')
            ->append('menu_name','require')
            ->remove('route','require');
    }

}